package com.szholly.pro.watergas_server.ps.android.common;

import java.io.Serializable;

import net.sf.json.JSONObject;

/**
 * Android数据返回封装类
 * 
 * code 0表示失败 1表示成功
 * 
 * message 提示信息
 * 
 * noticeMethod 提示信息手段 支持两种(toast dialog)
 * 
 * data 数据
 * 
 * 2017/3/23 <br/>
 *
 * @author Joey Huang QQ:273179370）
 */
public class ResultBean implements Serializable{
	private static final long serialVersionUID = -8433157605198953712L;
	public static final String TOAST = "toast";
	public static final String DIALOG = "dialog";
	private boolean success;
	private String message;
	private String noticeMethod;
	private String data;

	public ResultBean() {
		this(false);
	}
	
	public ResultBean(boolean success) {
		this(success,null);		
	}
	
	public ResultBean(boolean success, String message) {
		this(success,message,null);
	}
	
	public ResultBean(boolean success, String message, String noticeMethod) {
		this(success,message,noticeMethod,null);
	}

	public ResultBean(boolean success, String message, String noticeMethod, String data) {
		this.success = success;
		this.message = message;
		this.noticeMethod = noticeMethod;
		this.data = data;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public void setMessage(String message) {
		this.message = message;
	}
		
	public void setNoticeMethod(String noticeMethod) {
		this.noticeMethod = noticeMethod;
	}

	public void setData(String data) {
		this.data = data;
	}

	/**
	 * 生成JSON数据
	 */
	public String toJSONString() {
		JSONObject resultJsonObject = new JSONObject();
		String code = success ? "1" : "0";
		resultJsonObject.put("code", code);
		if (message !=null) {
			resultJsonObject.put("message", message);
		}
		if (noticeMethod!=null) {
			resultJsonObject.put("noticeMethod", noticeMethod);
		}else{
			resultJsonObject.put("noticeMethod", TOAST);
		}		
		if (data!=null) {
			resultJsonObject.put("data", data);
		}
		return resultJsonObject.toString();
	}

	public String toString() {
		return toJSONString();
	}
}
